package com.archway.nearshop.zdemo.ademo.mvc;

import java.util.HashMap;
import java.util.List;
import java.util.Map;



import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.archway.appframe.web.auth.session.SessionBean;
import com.archway.appframe.web.servlet.bind.InputObject;
import com.archway.appframe.web.servlet.bind.OutputObject;
import com.archway.nearshop.zdemo.ademo.domain.TestTable;
import com.archway.nearshop.zdemo.ademo.service.interfaces.IMyBatisDemoSV;

@Controller /*控制器类*/
@RequestMapping("/test") /*整个类都将强制处理 /test目录的请求*/
public class TestController {


	private static Logger log = LoggerFactory.getLogger(TestController.class);
	
    @Autowired
    private SessionBean sessionBean;

    
    @Autowired
	private IMyBatisDemoSV sv;
    
	@RequestMapping(value="/get/{id}/{name}" ,method=RequestMethod.GET) 
	public @ResponseBody OutputObject testHttpGet(@PathVariable String id,@PathVariable String name) throws Exception {//,Map<String, Object> model
		OutputObject output = new OutputObject();
		Map<String,Object> map = new HashMap<String,Object>();
		//插入内容
		sv.insert();
		//查出内容
		List<TestTable> tableList = sv.getAll();
		for (int i = 0; i < tableList.size(); i++) {
			TestTable tableItem = tableList.get(i);
			System.out.println(tableItem.toString());
			map.put(i+"", tableItem.toString());
		}
		
		
		//System.out.println("testDemoInGet " + id + "-" );

		
		//map.put("sys", table.getContent());
		//System.out.println(OrginTask.icecream);
		output.setBean(map);
		return output;
		//return "home444";
	}
	
	@RequestMapping(value="/post" ,method=RequestMethod.POST) 
	public @ResponseBody OutputObject testHttpPost(@RequestBody InputObject inputObject) throws Exception {//,Map<String, Object> model
		
		log.debug((String)inputObject.get("id"));
		OutputObject output = new OutputObject(); 
		//System.out.println(requestInfo);
		
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("000", "浙江省");
		map.put("571", "杭州");
		map.put("577", "温州");
		output.setBean(map);
		return output;
	}
	
	
	@RequestMapping(value="/getById/{id}" ,method=RequestMethod.GET) 
	public @ResponseBody OutputObject testDBGetById(@PathVariable String id) throws Exception {
		
		log.debug(id);
		OutputObject output = new OutputObject(); 
		//System.out.println(requestInfo);
		
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("000", "浙江省");
		map.put("571", "杭州");
		map.put("577", "温州");
		output.setBean(map);
		return output;
	}
	
	
	
}
